﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Linq;
using JamesZhao.Engine.Graphics;
using JamesZhao.Engine.Graphics.Surfaces;

namespace JamesZhao.Engine.Utils
{
    public partial class RenderPipelineVisualizer : Form
    {
        public RenderPipelineVisualizer()
        {
            InitializeComponent();
        }

        public RenderPipeline Pipeline { get; set; }
        public ColorSurface Output { get; set; }
        /// <summary>
        /// requires all the surfacevisualizers to be added to the render stages
        /// </summary>
        public void InitalizeEntries()
        {
            listBox1.DisplayMember = "Name";
            foreach (var stage in Pipeline.RenderStages)
            {
                if (stage is SurfaceVisualizer)
                {
                    var visualizer = stage;
                    listBox1.Items.Add(visualizer);
                    visualizer.FinalColorSurface = Output;
                }
            }
            listBox1.SelectedIndex = 0;

        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            
            foreach (var stage in Pipeline.RenderStages)
            {
                if (stage is SurfaceVisualizer)
                {
                    var visualizer = (SurfaceVisualizer)stage;
                    visualizer.Enabled = false;
                }
            }
            if(listBox1.SelectedItem!=null)
            {
                ((SurfaceVisualizer) listBox1.SelectedItem).Enabled = true;
            }
        }
    }
}
